package iot.core.util;

import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.cfg.MapperConfig;
import com.fasterxml.jackson.databind.introspect.AnnotatedMethod;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class MyJSONPropertyNamingStrategy extends PropertyNamingStrategy {
    @Override
    public String nameForGetterMethod(MapperConfig<?> config, AnnotatedMethod method, String defaultName) {
        var mname=method.getName();
        if(mname.startsWith("is")){
            return method.getName().substring(2);
        }else if  (mname.startsWith("get")){
            return method.getName().substring(3);
        }else{
            return super.nameForSetterMethod(config,method,defaultName);
        }
    }
    @Override
    public String nameForSetterMethod(MapperConfig<?> config, AnnotatedMethod method, String defaultName) {
        var mname=method.getName();
        if(mname.startsWith("is")){
            return method.getName().substring(2);
        }else if  (mname.startsWith("get")){
            return method.getName().substring(3);
        }else{
            return super.nameForSetterMethod(config,method,defaultName);
        }
    }


}
